window.onload=bodyLoad;

var allCollapsed = false;
var allExpanded = false;

function documentElement(id)
{
	return document.getElementById(id);
}

function sourceElement(e)
{
	if (window.event)
		e = window.event;
	return e.srcElement? e.srcElement : e.target;
}

function dxBeforePrint()
{
	var i;
	var allElements;

	if (window.text) document.all.text.style.height = "auto";
	
	allElements = document.getElementsByTagName("*");
			
	for (i=0; i < allElements.length; i++)
	{
		if (allElements[i].tagName == "body") 
		{
			allElements[i].scroll = "yes";
		}
		if (allElements[i].id == "pagetop") 
		{
			allElements[i].style.margin = "0px 0px 0px 0px";
			allElements[i].style.width = "100%";
		}
		if (allElements[i].id == "pagebody") 
		{
			allElements[i].style.overflow = "visible";
			allElements[i].style.top = "5px";
			allElements[i].style.width = "100%";
			allElements[i].style.padding = "0px 10px 0px 30px";
		}
		if (allElements[i].id == "seealsobutton") 
		{
			allElements[i].style.display = "none";
		}
	}
}

function dxAfterPrint()
{
	 document.location.reload();
}    

function bodyLoad()
{
	SetCollapseAll();
	SplitWindow();
	window.onbeforeprint = dxBeforePrint;
	window.onafterprint = dxAfterPrint;	
}

function bodyResize()
{
	SplitWindow();
}

function SplitWindow()
{ 
	var screen = new SplitScreen('pagetop', 'pagebody');       
} 

function SplitScreen (nonScrollingRegionId, scrollingRegionId) 
{
	this.nonScrollingRegion = document.getElementById(nonScrollingRegionId);
	this.scrollingRegion = document.getElementById(scrollingRegionId);
	document.body.scroll = "no";
	document.body.style.margin = "0px";
	document.body.style.overflow = "hidden";
	if(this.scrollingRegion)
	{
		this.scrollingRegion.style.overflow = "auto";
	}
	this.resize(null);
	RegisterEventHandler(window, 'resize', GetInstanceDelegate(this, "resize"));
}

SplitScreen.prototype.resize = function(e) 
{
	if(this.scrollingRegion)
	{
		this.scrollingRegion.style.height = document.body.clientHeight - this.nonScrollingRegion.offsetHeight;
		this.scrollingRegion.style.width = document.body.clientWidth;
	}
}

function RegisterEventHandler (element, event, handler) 
{
	if (element.attachEvent) 
	{
		element.attachEvent('on' + event, handler);
	} 
	else if (element.addEventListener) 
	{
		element.addEventListener(event, handler, false);
	} 
	else 
	{
		element[event] = handler;
	}
}


function GetInstanceDelegate (obj, methodName) 
{
	return( function(e) {
		e = e || window.event;
		return obj[methodName](e);
	} );
}

function ExpandCollapse(prefixSection)
{
	imageItem = document.getElementById(prefixSection+"Toggle");

	if (imageItem.src == collapseImage.src)
	{
		imageItem.src = expandImage.src;
		imageItem.alt = expandImage.alt;
		CollapseSection(prefixSection+"Section");		
	}
	else
	{
		imageItem.src = collapseImage.src;
		imageItem.alt = collapseImage.alt;
		ExpandSection(prefixSection+"Section");
	}
	var imgElements = document.getElementsByTagName('IMG');
	allCollapsed = true;
	allExpanded = true;
	for (i = 0; i < imgElements.length; ++i)
	{
		if(imgElements[i].className == "toggle")
		{
			if(imgElements[i].src == collapseImage.src)
			{
				allCollapsed = false;
			}			
			if(imgElements[i].src == expandImage.src)
			{
				allExpanded = false;
			}			
		}
	}
	SetCollapseAll();
}	

function SubExpandAll(imgElements)
{
		for (i = 0; i < imgElements.length; ++i)
		{
			if(imgElements[i].className == "toggle")
			{
				imgElements[i].src = collapseImage.src;
				imgElements[i].alt = collapseImage.alt;			
			}
			if(imgElements[i].className == "section")
			{
				ExpandSection(imgElements[i].id);
			}
			
		}
}
function SubCollapseAll(imgElements)
{
		for (i = 0; i < imgElements.length; ++i)
		{
			if(imgElements[i].className == "toggle")
			{
				imgElements[i].src = expandImage.src;
				imgElements[i].alt = expandImage.alt;
			}
			if(imgElements[i].className == "section")
			{
				CollapseSection(imgElements[i].id);
			}
		}
}

function ExpandCollapseAll(imageItem)
{   
	var imgElements1 = document.getElementsByTagName('IMG');
	var imgElements2 = document.getElementsByTagName('DIV');
	var i;
	if (imageItem.src == expandImage.src)
	{
		imageItem.src = collapseImage.src;
		imageItem.alt = collapseImage.alt;
		SubExpandAll(imgElements1);
		SubExpandAll(imgElements2);
		SetToggleAllLabel(false);
		
		allExpanded = true;
		allCollapsed = false;
	}
	else
	{	
		imageItem.src = expandImage.src;
		imageItem.alt = expandImage.alt;
		SubCollapseAll(imgElements1);
		SubCollapseAll(imgElements2);		
		SetToggleAllLabel(true);
		
		allExpanded = false;
		allCollapsed = true;
	}
}

function ExpandCollapse_CheckKey(sectionId)
{
	if(window.event.keyCode == 13)
		ExpandCollapse(sectionId);
}

function ExpandCollapseAll_CheckKey(sectionId)
{
	if(window.event.keyCode == 13)
		ExpandCollapseAll(sectionId);
}

function ExpandSection(sectionId)
{
//	try
    	//{
		document.getElementById(sectionId).style.display	= "";
    	//}
    	//catch(){}
}

function CollapseSection(sectionId)
{
		//try
    	//{	    
		document.getElementById(sectionId).style.display	= "none";
    	//}
    	//catch (){}
}

function SetCollapseAll()
{
	var imageElement = document.getElementById("toggleAllImage");
	
	if (imageElement == null) return;
	
	if (allCollapsed)
	{
		imageElement.src = expandImage.src;
		imageElement.alt = expandImage.alt;
	}
	else
	{
		imageElement.src = collapseImage.src;
		imageElement.alt = collapseImage.alt;
	}
	
	SetToggleAllLabel(allCollapsed);
}

function SetToggleAllLabel(collapseAll)
{
	var labelElement = document.getElementById("collapseAllLabel");
	
	if (labelElement == null) return;
		
	labelElement.style.display = "none";
	
	labelElement = document.getElementById("expandAllLabel");
	labelElement.style.display = "none";
	
	if (collapseAll)
	{
		labelElement = document.getElementById("expandAllLabel");
		labelElement.style.display = "inline";
	}
	else
	{
		labelElement = document.getElementById("collapseAllLabel");
		labelElement.style.display = "inline";
	}
}

